package com.li.taskcenter.controller.taskdefine;

import com.li.configserve.controller.BaseController;
import com.li.configserve.domain.gloabreturn.ResponseInfo;
import com.li.taskcenter.domain.taskcenter.TaskDefine;
import com.li.taskcenter.service.taskdefine.TaskDefineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description：TaskDefineController
 * @Author：LiDong
 * @Create：2020/11/24
 * @Version：1.0.0
 */
@Api(tags = {"任务定义类"})
@RestController
@RequestMapping("/taskdefine")
public class TaskDefineController extends BaseController {

    @Autowired
    private TaskDefineService taskDefineService;

    @Autowired
    private RestTemplate restTemplate;

    @ApiOperation(value = "任务定义分页列表查询")
    @RequestMapping("/page")
    public ResponseInfo pageTaskDefines() {
        return taskDefineService.pageTaskDefines(getParamMap(request));
    }

    @ApiOperation(value = "任务定义新增")
    @PostMapping(value ="/add")
    public ResponseInfo addTaskDefine(@RequestBody TaskDefine taskDefine) {
        return taskDefineService.addTaskDefine(taskDefine);
    }


    @RequestMapping("/test1")
    public ResponseInfo test1(){
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setMessage("Hellow");
        responseInfo.setCode(200);
        responseInfo.setData("测试成功");

        // 传的参数
        Map<String, Object> parameters = new HashMap<>(4);
        parameters.put("grant_type", "client_credential");
        String s = restTemplate.postForObject("http://oscoreserver/test/test1", parameters, String.class);
        responseInfo.setData(s);
        return responseInfo;
    }

}
